#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3e5 + 5;

int n, m;
vector<int> a[N];
int b[N];
int c[N];
int d[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m) {
    int k;
    cin >> k;
    a[i] = vector<int>(k);
    rep(j, 0, k - 1) cin >> a[i][j];
  }
  rep(i, 1, n) cin >> b[i];
  rep(i, 1, n) c[b[i]] = i;
  rep(i, 1, m) {
    for (int x : a[i]) d[i] = max(d[i], c[x]);
  }
  sort(d + 1, d + m + 1);
  rep(i, 1, n) {
    int cnt = upper_bound(d + 1, d + m + 1, i) - d - 1;
    cout << cnt << endl;
  }
  return 0;
}